{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=[1,2]\n",
    "b=a[:] #浅拷贝\n",
    "a[0]=10\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import copy\n",
    "a=[1,2]\n",
    "b=[3,4]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[10, 2], [3, 4]]\n",
      "[[10, 2], [3, 4]]\n"
     ]
    }
   ],
   "source": [
    "c=[a,b]\n",
    "d=c.copy()\n",
    "a[0]=10\n",
    "print(c)\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2315141712384\n",
      "2315141763392\n"
     ]
    }
   ],
   "source": [
    "print(id(c))\n",
    "print(id(d))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[10, 2], [3, 4]]\n",
      "[[10, 2], [3, 4]]\n"
     ]
    }
   ],
   "source": [
    "a=[1,2]\n",
    "b=[3,4]\n",
    "c=[a,b]\n",
    "d=copy.deepcopy(c)  #深拷贝,递归进行拷贝，直到拷贝的元素不再是可变对象为止\n",
    "a[0]=10\n",
    "print(c)\n",
    "print(d)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
